package tongcheng.com.tongcheng.base.main.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yanzhenjie.nohttp.RequestMethod;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import butterknife.Bind;
import tongcheng.com.tongcheng.ConStans;
import tongcheng.com.tongcheng.R;
import tongcheng.com.tongcheng.base.BaseActivity;
import tongcheng.com.tongcheng.network.CallServer;
import tongcheng.com.tongcheng.network.MyRequest;
import tongcheng.com.tongcheng.network.OnCallBack;

public class WebViewActivity extends BaseActivity {

    @Bind(R.id.back)
    ImageView mBack;
    @Bind(R.id.title)
    TextView mTitle;
    @Bind(R.id.title_bar)
    RelativeLayout mBg;
    @Bind(R.id.webView)
    WebView webView;
    private String data = "";

//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_web_view);
//    }

    @Override
    public Integer initResid() {
        return R.layout.activity_web_view;
    }

    @Override
    public void initCreate(Bundle savedInstanceState) {
        settitlebar(mBg);

        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        int key = getIntent().getIntExtra("keyword",0);
        String text = getIntent().getStringExtra("title");
        mTitle.setText(text);
        getNetData(key);

    }

    private void getNetData(int keyword) {
        MyRequest request = new MyRequest(ConStans.GuanYuWoMenUrl, RequestMethod.GET);
        request.add("keyword",keyword);
        Log.e("关键字",keyword + "");
        CallServer.getInstance().addGet(2, new OnCallBack() {
            @Override
            public void OnSuccess(int what, String json, Object ject) {
                try {
                    JSONObject object = new JSONObject(json);
                    if(object.getInt("status") == 1){
                        JSONObject object1 = object.getJSONObject("data");
                        data = object1.getString("details");
                        webView.loadDataWithBaseURL("about:blank", data, "text/html", "utf-8", null);

                        Log.e("关于我们",data);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                Log.e("关于我们",json);
            }
        }, request);

    }


    private String blank = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

    private String notice1 = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>" +
            "<h3 align='center'>关于关闭电话银行语音系统查询动态密码功能的公告</h3></head>"
            + "<body>"
            + "<p align='center'><i>发布日期：2011-04-25</i>"
            + "</p><p>尊敬的客户："
            + "</p><p>" + blank +
            "根据优化电话银行相关服务功能的整体安排，我行决定自4月25日起，在95595电话银行语音系统中，停止受理查询手机动态密码功能。给您带来的不便之处敬请谅解。如有问题，请致电我行24小时服务热线95595。"
            + "</p><p>" + blank +
            "感谢您长期以来对我行的关注、支持与厚爱!"
            + "</p><p>" + blank +
            "特此公告。"
            + "</p><p align='right'>中国光大银行"
            + "</p><p align='right'>2011年4月25日</p></body></html>";


    private String fmtString(String str){
        String notice = "";
        try{
            notice = URLEncoder.encode(str, "utf-8");
        }catch(UnsupportedEncodingException ex){

        }
        return notice;
    }

}
